package br.ufrn.sigtcc.controller.cadastros;

import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.primefaces.event.FlowEvent;

import br.ufrn.sigtcc.controller.cadastros.interfaces.IControleCadastroProfessor;
import br.ufrn.sigtcc.controller.services.ProfessorServiceImpl;
import br.ufrn.sigtcc.model.entidades.Endereco;
import br.ufrn.sigtcc.model.entidades.Professor;
import br.ufrn.sigtcc.model.entidades.Telefone;
import br.ufrn.sigtcc.util.exceptions.BDException;
import br.ufrn.sigtcc.util.exceptions.BusinessException;

@ManagedBean(name="professorBean")
@SessionScoped
public class ControleCadastroProfessor extends ProfessorServiceImpl implements IControleCadastroProfessor{

	public ControleCadastroProfessor() {
		// TODO Auto-generated constructor stub
	}
	
	private Professor professor =  new Professor();
	private Endereco endereco =  new Endereco();
	private Telefone telefone =  new Telefone();
	
	
	public Professor getProfessor() {
		return professor;
	}

	public void setProfessor(Professor professor) {
		this.professor = professor;
	}

	public Endereco getEndereco() {
		return endereco;
	}

	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}

	public Telefone getTelefone() {
		return telefone;
	}

	public void setTelefone(Telefone telefone) {
		this.telefone = telefone;
	}

	@Override
	public void cadastrarProfessor() throws BDException, BusinessException {

	//	professor.setEndereco(endereco);
	//	professor.setTelefone(telefone);
		
		cadastrarProfessor(professor);
	}

	@Override
	public void removerProfessor() throws BDException, BusinessException {

		removerProfessor(professor);
		
	}

	@Override
	public void atualizarProfessor() throws BDException, BusinessException {

		atualizarAluno(professor);
	}
	
private boolean skip;
	
	private static Logger logger = Logger.getLogger(ControleCadastroProfessor.class.getName());

	public void cadastrarProfessor(ActionEvent actionEvent) throws BDException, BusinessException {

		cadastrarProfessor();
		
		FacesMessage msg = new FacesMessage("Sucesso", "Bem Vindo :" + professor.getNome());
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}
	
	public boolean isSkip() {
		return skip;
	}

	public void setSkip(boolean skip) {
		this.skip = skip;
	}
	
	public String onFlowProcess(FlowEvent event) {
		logger.info("Passo Corrente:" + event.getOldStep());
		logger.info("Proximo passo:" + event.getNewStep());
		
		if(skip) {
			skip = false;	
			return "confirm";
		}
		else {
			return event.getNewStep();
		}
	}

}
